<%@ page language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Retrive username pw</title>

<%
		Connection conn = null;
		Class.forName("org.sqlite.JDBC");
		conn = DriverManager.getConnection("jdbc:sqlite://Users/Annie/Documents/workspace/HomeFinders/homefinders.db");
		ResultSet rsdoLogin = null;
		Statement psdoLogin=null;
		psdoLogin = conn.createStatement();
		String sEmail=request.getParameter("sEmail");
		System.out.println(sEmail);
		String sqlOption="SELECT * FROM login where email ='" + sEmail + "';";
		String message = null;
		//rsdoLogin=psdoLogin.executeQuery(sqlOption); 
		System.out.println(sqlOption);
    
    	try{
 		    rsdoLogin=psdoLogin.executeQuery(sqlOption);   
 		   if (!rsdoLogin.next())
 			{
 				message = "No Username and Password match "+sEmail;
 				response.sendRedirect("forgetpw.jsp?error="+message);
 	   	  		System.out.println(message);
 			}
 		   else
 		   {
 		    	  String sPw=rsdoLogin.getString("pw");
 		    	  String sUsername=rsdoLogin.getString("username");
 		    	  System.out.println("Email content: "+sUsername + " " + sPw);
 		    	  message = "Username and Password have been sent to "+sEmail;
 		    	  System.out.println(message);
 		    	  response.sendRedirect("login.jsp?error="+message);
 		    	  //alert(message);
 		    }
    	}
     catch(Exception e){e.printStackTrace();}
     
     try{
         if(psdoLogin!=null){psdoLogin.close();}
         
         if(rsdoLogin!=null){rsdoLogin.close();}
         
         if(conn!=null){conn.close();}
        }
    	catch(Exception e){e.printStackTrace();}
    
%>

<script type="text/javascript">
var message = "<%= message %>";
alert('<%= message %>');
</script>

